package com.oriental.manage.controller.specially;

import com.alibaba.dubbo.rpc.RpcException;
import com.oriental.manage.core.paging.Pagination;
import com.oriental.manage.core.response.ResponseDTO;
import com.oriental.manage.service.specially.RiskSearchService;
import com.oriental.riskfront.api.model.CommercialRiskBody;
import com.oriental.riskfront.api.model.PersonalRiskBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by guzhe on 2017/4/20.
 */
@Slf4j
@Controller
@RequestMapping("riskInfo")
public class RiskSearchController {


@SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    private RiskSearchService riskSearchService;

    @RequestMapping("personRiskQuery/init")
    public String initPersonInfo() {
        return "specially/queryPersonRiskI";
    }

    @RequestMapping("personRiskQuery/search")
    @ResponseBody
    public ResponseDTO<Pagination<PersonalRiskBody>> queryPersonRiskPage(Pagination<PersonalRiskBody> pagination, PersonalRiskBody personalRiskInfo) {
        ResponseDTO<Pagination<PersonalRiskBody>> responseDTO = new ResponseDTO<Pagination<PersonalRiskBody>>();
        try {
            riskSearchService.queryPersonRiskPage(pagination, personalRiskInfo);
            responseDTO.setSuccess(true);
            responseDTO.setObject(pagination);
        }catch (RpcException exception){
            log.error(exception.getMessage(),exception);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("连接异常!");
        } catch (Exception e) {
            log.error("查询失败", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg(e.getMessage());
        }
        return responseDTO;
    }

    @RequestMapping("personRiskQuery/personRiskDetail")
    public String personRiskDetail() {

        return "specially/personRiskDetailI";
    }

    @RequestMapping("merchantRiskQuery/init")
    public String initMerchantInfo() {
        return "specially/queryMerchantRiskI";
    }

    @RequestMapping("merchantRiskQuery/search")
    @ResponseBody
    public ResponseDTO<Pagination<CommercialRiskBody>> queryMerchantPage(Pagination<CommercialRiskBody> pagination, CommercialRiskBody commercialRiskInfo) {
        ResponseDTO<Pagination<CommercialRiskBody>> responseDTO = new ResponseDTO<Pagination<CommercialRiskBody>>();
        try {
            riskSearchService.queryMerchantPage(pagination, commercialRiskInfo);
            responseDTO.setSuccess(true);
            responseDTO.setObject(pagination);
        }catch (RpcException exception){
            log.error(exception.getMessage(),exception);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("连接异常!");
        }  catch (Exception e) {
            log.error("查询失败", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg(e.getMessage());
        }
        return responseDTO;
    }

    @RequestMapping("merchantRiskQuery/merchantRiskDetail")
    public String merchantRiskDetail() {
        return "specially/merchantRiskDetailI";
    }
}
